package com.ccl.iot.device;

import android.os.Parcel;
import android.os.Parcelable;

/**
 * @description：安防主机的单个分区
 * @author： HD
 * @time：2017/5/3
 */
public class ArmPartitionInfo implements Parcelable {

    /**
     * 分区的信息
     */
    private byte[] mReg = new byte[6];

    /**
     * 地址的起始位
     */
    private int mAddress = 0;

    /**
     * 布防的状态
     */
    private byte mState;

    /**
     * 布防的类型
     */
    private byte mType;

    /**
     * 密码
     */
    private byte[] mParam = new byte[4];

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeByteArray(this.mReg);
        dest.writeInt(this.mAddress);
        dest.writeByte(this.mState);
        dest.writeByte(this.mType);
        dest.writeByteArray(this.mParam);
    }

    protected ArmPartitionInfo(Parcel in) {
        this.mReg = in.createByteArray();
        this.mAddress = in.readInt();
        this.mState = in.readByte();
        this.mType = in.readByte();
        this.mParam = in.createByteArray();
    }

    public static final Parcelable.Creator<ArmPartitionInfo> CREATOR = new Parcelable.Creator<ArmPartitionInfo>() {
        @Override
        public ArmPartitionInfo createFromParcel(Parcel source) {
            return new ArmPartitionInfo(source);
        }

        @Override
        public ArmPartitionInfo[] newArray(int size) {
            return new ArmPartitionInfo[size];
        }
    };


    public ArmPartitionInfo(byte[] data, int address) {
        mReg = data;
        mAddress = address;

        setState(data);
        setType(data);
        setParam(data);
    }

    public void setRegDatas(byte[] newData) {
        mReg = newData;
    }

    public byte[] getRegDatas() {
        return mReg;
    }

    public byte getState() {
        return mState;
    }

    public void setState(byte state) {
        this.mState = state;
    }

    private void setState(byte[] data){
        mState = data[0];
    }

    public byte getType() {
        return mType;
    }

    public void setType(byte type) {
        this.mType = type;
    }

    private void setType(byte[] data){
        mType = data[1];
    }

    public byte[] getParam() {
        return mParam;
    }

    private void setParam(byte[] data) {
        this.mParam[0] = data[2];
        this.mParam[1] = data[3];
        this.mParam[2] = data[4];
        this.mParam[3] = data[5];
    }

}
